<?php

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.controller' );

class AuctionControllerHistory extends JController
{
	function __construct( $default = array())
	{
		parent::__construct( $default );
	}

	function display() 
	{
	   parent::display();
	}
	
	function restore(){
		$db = JFactory::getDBO();
		$id = JRequest::getVar('id');
		
		$query = "SELECT auction_date FROM #__auction_date WHERE id = 1";
		$db->setQuery($query);
		$auction_date = $db->loadResult();
		
		$query = "UPDATE #__auction SET currentprice = 500, auction_date = '".$auction_date."',winprice = 0, winid = '', closed = 0 WHERE id = ".$id;
		$db->setQuery($query);
		$db->query();
		
		$query = "DELETE FROM #__auction_user WHERE auction_id = ".$id;
		$db->setQuery($query);
		$db->query();
		
		$query = "SELECT product_id FROM #__auction WHERE id = ".$id;
		$db->setQuery($query);
		$proid = $db->loadResult();
		
		$query = "UPDATE #__pr_product SET bought = 0 WHERE id = ".$proid;
		$db->setQuery($query);
		$db->query();
		
		$this->setRedirect('index.php?option=com_auction&controller=history','A auction is restored');
	}
} 